www.gusucode.com > VC 2D游戏编辑器-源码程序 > VC 2D游戏编辑器-源码程序/code/game_Source/newgame.cpp

    //Download by http://www.NewXing.com
#include <ddraw.h>
#include <math.h>
#include "main.h"
#include "newgame.h"
#include "exit.h"
#include "savegame.h"
#include "loadgame.h"

void NextDirRole( );
void NextDirZoetic(int id);
void ShowRoleInfo( );
void newgame_FreeAll( );
void JudgeMousePlace( );
void ShowSelectInfo(long lW, long lH);
void UseEquip(int id);
void RemoveEquip(int id);
void PlayMagic(MagicIsUsing *magic);
void MoveTheRole(int tt);
void MoveTheZoetic(int tt, int id);
void AddMagicToLink( );
void ChangeTheDynamicPic( );
void MovZoetic( );
void MovRole( );
void ChangeMagicStatus( );
void ChangeAttackTextStatus( );
void AddMagicToLink( );
void IsMouseOnSomeone( );

void Show_AttackText(AttackText * TextLink);

bool	NewGameOut;
bool	IsMove;			//判断是否进行鼠标拖动
bool	IsMoveGoods;
bool	IsMoveMagic;
bool	IsShowStatusBMP;
bool	IsShowSelect;
bool	IsDelParameter;
int		NewGameSelect;
int		iLineN;
int		iArrowN;
int		iStatusW;		//工具栏显示的长度,用于工具栏缓慢显示
int		iSelect;
int		iSelectSkill;
int		id_newgame;		//鼠标所在位置的事件号
int		iMouseInZoetic;
RECT	rect;
GOODS	moveGoods;
SKILL	moveMagic;


CGoods MainGoods("Resource\\1.goods");
CMagic MainMagic("Resource\\1.magic");
CScript MainScript;

BMPHEADER * statusBMP;
BMPHEADER * medica_shelfBMP;
BMPHEADER * goods_explainBMP;
BMPHEADER * equip_shelfBMP;
RLEBITHEADER * lineRLE;
RLEBITHEADER * healthRLE;
RLEBITHEADER * energyRLE;
RLEBITHEADER * vigorRLE;
RLEBITHEADER * goodsRLE;
RLEBITHEADER * magicRLE_tool;
RLEBITHEADER * arrowRLE;
RLEBITHEADER * newgame_selectRLE;
RLEBITHEADER * newgame_titleRLE;
RLEBITHEADER * goods_selectedRLE;
RLEBITHEADER * man_equipRLE;
RLEBITHEADER * system_sel1RLE;
RLEBITHEADER * system_sel2RLE;
RLEBITHEADER * system_unsel_textRLE;
RLEBITHEADER * system_sel_textRLE;
RLEBITHEADER * LostRLE;
RLEBITHEADER * PurposeRLE;


int NewGame( )
{
	role = new ROLE(TMain, 0, 192, TMain);
	MainScript.LoadNewScript(0xffff, "logo.ini", "Resource\\script\\logo.ini");
	MainScript.iPosition = 0;
	return(StartGame( ));
}
int StartGame( )
{
	mainMusic->LoadMusic("music\\Story.mid");
	mainMusic->Play( );
	char filename[32];
	char result[MAX_PATH];
	int i;
	MSG msg;
	iTimes = 1;
	NewGameOut = false;
	IsMove	= false;
	bFirstDrawMap = true;
	IsShowStatusBMP = true;
	IsShowSelect = false;
	IsMoveGoods = false;
	IsMoveMagic = false;
	IsDelParameter = false;
	iSelectSkill = 0;
	NewGameSelect = 0;
	PurposeTimes = 0;
	time = 0;
	iMouseInZoetic = -1;
	GameSpeed = 4;
	if(magic_using)
	{
		while(magic_using->Next)
		{
			magic_using = magic_using->Next;
			P_SAFE_DELETE(magic_using->Back);
		}
		P_SAFE_DELETE(magic_using);
	}
	iLineN = 0;
	iArrowN = 0;
	iSelect = 1;
	GameStatus = GAME_NORMAL;
	rect.left = 0;
	rect.top = 0;
	rect.right = rect.left + (SW[SMap]>>5);
	rect.bottom = rect.top + (SH[SMap]>>5);
	if(bIsLoadCell == false)
	{
		OpenCellFile( );
		LoadCell( );
		bIsLoadCell = true;
	}
	if(!bIsGameLoadGame)
	{
		Role_Pic				= LoadRleImage("pic\\human\\character.ret");
		statusBMP				= LoadBMPImage("pic\\interface\\status.cb",0, false);
		medica_shelfBMP			= LoadBMPImage("pic\\goods\\medica_shelf.cb", 0, false);
		goods_explainBMP		= LoadBMPImage("pic\\goods\\goods_explain.cb", 0, false);
		equip_shelfBMP			= LoadBMPImage("pic\\goods\\equip_shelf.cb", 0, false);
		lineRLE					= LoadRleImage("pic\\interface\\line.ret");
		healthRLE				= LoadRleImage("pic\\interface\\man_health.ret");
		energyRLE				= LoadRleImage("pic\\interface\\man_energy.ret");
		vigorRLE				= LoadRleImage("pic\\interface\\man_vigor.ret");
		goodsRLE				= LoadRleImage("pic\\goods\\goods.ret");
		magicRLE_tool			= LoadRleImage("pic\\goods\\magic.ret");
		arrowRLE				= LoadRleImage("pic\\cursor\\arrow.ret");
		newgame_selectRLE		= LoadRleImage("pic\\dialog\\select.ret");
		newgame_titleRLE		= LoadRleImage("pic\\dialog\\title.ret");
		goods_selectedRLE		= LoadRleImage("pic\\goods\\selected.ret");
		man_equipRLE			= LoadRleImage("pic\\goods\\equip_man.ret");
		system_sel1RLE			= LoadRleImage("pic\\dialog\\dialog1.ret");
		system_sel2RLE			= LoadRleImage("pic\\dialog\\dialog2.ret");
		system_unsel_textRLE	= LoadRleImage("pic\\dialog\\unselecttext.ret");
		system_sel_textRLE		= LoadRleImage("pic\\dialog\\selecttext.ret");
		magicRLE_user			= LoadRleImage("pic\\magic\\magic_user.ret");
		PurposeRLE				= LoadRleImage("Pic\\cursor\\cursor02.ret");
		for(i = 0; i < MaxSkill; i++)
		{
			strcpy(result,"pic\\magic\\magic");
			itoa(i, filename, 10);
			strcat(result, filename);
			strcat(result, ".ret");
			magicRLE[i] = LoadRleImage(result);
		}
		for(i = 0; i < MaxNPC_Pic; i++)
		{
			strcpy(result,"pic\\human\\NPC-");
			itoa(i, filename, 10);
			strcat(result, filename);
			strcat(result, ".ret");
			Zoetic_Pic[i] = LoadRleImage(result);
		}
		Goods = &MainGoods;
		Magic = &MainMagic;
		Script = &MainScript;
		OpenScriptInit( );
	}
	cursor = 0;
	PA_SAFE_DELETE(mouseRLE);
	mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
	cursorT = 4;
	iMouseType = 3;
	iStatusW = statusBMP->bfWidth;
mainloop:
	SetTimer(hwnd, 1, 50, NewGameTimer);
	Script->Run( );
	while(!NewGameOut)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if ( msg.message==WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else 
		{	
			NewGameRefreshScreen( );
		}			
	}
	KillTimer(hwnd, 1);

	switch(NewGameSelect)
	{
	case 1:
		gWPPStack.Push(lpWndProc);
	
		lpWndProc=ExitMessageProc;
		rect1 = MakeRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
		GraySurface(rect1);
		i = exit_func();
		gWPPStack.Pop(lpWndProc);
		if(2 == i)
		{
			NewGameOut = false;
			NewGameSelect = 0;
			if(iMouseType == 1)
			{
				cursor = 0;
				PA_SAFE_DELETE(mouseRLE);
				mouseRLE = LoadRleImage("Pic\\cursor\\cursor01.ret");
				cursorT = 4;
			}
			else if(iMouseType == 3)
			{
				cursor = 0;
				PA_SAFE_DELETE(mouseRLE);
				mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
				cursorT = 4;
			}

			goto mainloop;	
		}
		NewGameSelect = 1;
		break;
	case 2:
		gWPPStack.Push(lpWndProc);
	
		lpWndProc=SaveGameMessageProc;
		rect1 = MakeRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

		GraySurface(rect1);
		FastBlt(0, 0, rect1, pS[SBack], pS[SBuffer], SP[SBack], SP[SBuffer], false, 0);
		i = SaveGame_func();
		gWPPStack.Pop(lpWndProc);

		NewGameOut = false;
		NewGameSelect = 0;
		if(iMouseType == 1)
		{
			cursor = 0;
			PA_SAFE_DELETE(mouseRLE);
			mouseRLE = LoadRleImage("Pic\\cursor\\cursor01.ret");
			cursorT = 4;
		}
		else if(iMouseType == 3)
		{
			cursor = 0;
			PA_SAFE_DELETE(mouseRLE);
			mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
			cursorT = 4;
		}
		goto mainloop;	
		break;
	case 3:
		gWPPStack.Push(lpWndProc);
	
		lpWndProc=LoadGameMessageProc;
		rect1 = MakeRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

		GraySurface(rect1);
		FastBlt(0, 0, rect1, pS[SBack], pS[SBuffer], SP[SBack], SP[SBuffer], false, 0);
		i = LoadGame();
		gWPPStack.Pop(lpWndProc);
		if(i == 0xffff)
		{
			NewGameOut = false;
			NewGameSelect = 0;
			goto mainloop;	
		}
		NewGameSelect = 1;
		break;
	case 9:
		LostRLE = LoadRleImage("Pic\\interface\\lose.ret");
		rect1 = MakeRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
		GraySurface(rect1);
		ShowRleImage_NR((SCREEN_WIDTH-LostRLE->bfWidth)>>1, (SCREEN_HEIGHT-LostRLE->bfHeight)>>1,0, 0, LostRLE, pS[SBuffer], SP[SBuffer]);
		UpdateScreen();
		FadeIn(32, rect1, 100);
		NewGameSelect = 1;
		break;
	case 10:
		FadeIn(32, rect1, 100);
		NewGameSelect = 1;
		break;
	case 99:
		NewGameSelect = 1;
		break;
	default:
		break;
	}

	if(!IsDelParameter)
		newgame_FreeAll( );
	PA_SAFE_DELETE(mouseRLE);
	mouseRLE = LoadRleImage("pic\\cursor\\cursor01.ret");
	cursorT = 4;
	iMouseType = 1;
	return NewGameSelect;
}

void newgame_FreeAll( )
{
	PA_SAFE_DELETE(Role_Pic);
	PA_SAFE_DELETE(statusBMP);
	PA_SAFE_DELETE(lineRLE);
	PA_SAFE_DELETE(healthRLE);
	PA_SAFE_DELETE(energyRLE);
	PA_SAFE_DELETE(vigorRLE);
	PA_SAFE_DELETE(goodsRLE);
	PA_SAFE_DELETE(magicRLE_tool);
	PA_SAFE_DELETE(arrowRLE);
	PA_SAFE_DELETE(newgame_selectRLE);
	PA_SAFE_DELETE(newgame_titleRLE);
	PA_SAFE_DELETE(medica_shelfBMP);
	P_SAFE_DELETE(role);
	PA_SAFE_DELETE(goods_explainBMP);
	PA_SAFE_DELETE(equip_shelfBMP);
	PA_SAFE_DELETE(goods_selectedRLE);
	PA_SAFE_DELETE(man_equipRLE);
	PA_SAFE_DELETE(system_sel1RLE);
	PA_SAFE_DELETE(system_sel2RLE);
	PA_SAFE_DELETE(system_unsel_textRLE);
	PA_SAFE_DELETE(system_sel_textRLE);
	int i;
	for(i = 0; i < 10; i++)
	{
		if(Script_Child[i].Script != NULL)
		{
			PA_SAFE_DELETE(Script_Child[i].Script);
		}
	}
	for(i = 0; i < 18; i++)
		parameter[i] = NULL;
	for(i = 19; i < (int)ParameterHeader.nParameterN; i++)
		P_SAFE_DELETE(parameter[i]);
	PA_SAFE_DELETE(parameter);
	if(MainScript.Script != NULL)
		PA_SAFE_DELETE(MainScript.Script);
	IsDelParameter = true;
}

LRESULT WINAPI NewGameMessageProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
	int i, j;
	if(GameStatus != GAME_NORMAL)
		return DefWindowProc(hwnd, message, wParam, lParam);
	switch(message)
	{
	case WM_SETCURSOR:
		SetCursor(NULL);
		break;
	case WM_KEYDOWN:
		switch(wParam)
		{
		case VK_ESCAPE:
				IsShowSelect = !IsShowSelect;
				JudgeMousePlace( );
				if(id_newgame != 0)
				{
					if(iMouseType != 1)
					{
						cursor = 0;
						PA_SAFE_DELETE(mouseRLE);
						mouseRLE = LoadRleImage("Pic\\cursor\\cursor01.ret");
						cursorT = 4;
						iMouseType = 1;
					}
				}
				else if(iMouseType != 3)
				{
					cursor = 0;
					PA_SAFE_DELETE(mouseRLE);
					mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
					cursorT = 4;
					iMouseType = 3;
				}
				break;
		case VK_UP:
			if(role->speed < 15)
				role->speed += 2;
			break;
		case VK_DOWN:
			if(role->speed > 4)
				role->speed -= 2;
			break;
		case VK_RIGHT:
			if(GameSpeed > 1)
				GameSpeed -= 1;
			break;
		case VK_LEFT:
			if(GameSpeed < 20)
				GameSpeed += 1;
			break;
		case '1':
			if(role->tool_goods[0].id != -1)
			{
				Goods->UseGoods(role, 1, role->tool_goods[0].id);
				role->tool_goods[0].iNumber -= 1;
				if(role->tool_goods[0].iNumber == 0)
					role->tool_goods[0].id = -1;
			}
			break;
		case '2':
			if(role->tool_goods[1].id != -1)
			{
				Goods->UseGoods(role, 1, role->tool_goods[1].id);
				role->tool_goods[1].iNumber -= 1;
				if(role->tool_goods[1].iNumber == 0)
					role->tool_goods[1].id = -1;
			}
			break;
		case '3':
			if(role->tool_goods[2].id != -1)
			{
				Goods->UseGoods(role, 1, role->tool_goods[2].id);
				role->tool_goods[2].iNumber -= 1;
				if(role->tool_goods[2].iNumber == 0)
					role->tool_goods[2].id = -1;
			}
			break;
		case '4':
			if(role->tool_goods[3].id != -1)
			{
				Goods->UseGoods(role, 1, role->tool_goods[3].id);
				role->tool_goods[3].iNumber -= 1;
				if(role->tool_goods[3].iNumber == 0)
					role->tool_goods[3].id = -1;
			}
			break;
		case '5':
			if(role->tool_goods[4].id != -1)
			{
				Goods->UseGoods(role, 1, role->tool_goods[4].id);
				role->tool_goods[4].iNumber -= 1;
				if(role->tool_goods[4].iNumber == 0)
					role->tool_goods[4].id = -1;
			}
			break;
		case '6':
			if(role->tool_goods[5].id != -1)
			{
				Goods->UseGoods(role, 1, role->tool_goods[5].id);
				role->tool_goods[5].iNumber -= 1;
				if(role->tool_goods[5].iNumber == 0)
					role->tool_goods[5].id = -1;
			}
			break;
		case 112:	//F1
			if(role->tool_skill[0].id != -1)
			{
				iSelectSkill = 1;
			}
			break;
		case 113:	//F2
			if(role->tool_skill[1].id != -1)
			{
				iSelectSkill = 2;
			}
			break;
		case 114:	//F3
			if(role->tool_skill[2].id != -1)
			{
				iSelectSkill = 3;
			}
			break;
		case 115:	//F4
			if(role->tool_skill[3].id != -1)
			{
				iSelectSkill = 4;
			}
			break;
		case 116:	//F5
			if(role->tool_skill[4].id != -1)
			{
				iSelectSkill = 5;
			}
			break;
		case 117:	//F6
			if(role->tool_skill[5].id != -1)
			{
				iSelectSkill = 6;
			}
			break;
		default:
			return 1;
		}
		break;
	case WM_RBUTTONDOWN:
		curpos.x = LOWORD (lParam);
		curpos.y = HIWORD (lParam);
		if(iSelectSkill >0)
		{
			if((abs(curpos.x + dMap_StartX  - role->x) < (long)(Magic->Magic[role->tool_skill[iSelectSkill-1].id].wDistance<<5))
			 &&(abs(curpos.y + dMap_StartY - role->y) < (long)(Magic->Magic[role->tool_skill[iSelectSkill-1].id].wDistance<<5)))
			{
				if(role->Waittime != -1)
					break;
				if(!Magic->UseMagic(role, Magic->Magic[role->tool_skill[iSelectSkill-1].id].dType, role->tool_skill[iSelectSkill-1].id))
					break;
				role->Waittime = magicRLE_user->bfWidthBitN;
				role->MagicUsing.id = role->tool_skill[iSelectSkill-1].id;
				role->MagicUsing.x  = curpos.x+dMap_StartX;
				role->MagicUsing.y  = curpos.y+dMap_StartY;
				role->MagicUsing.n  = 0;
				role->MagicUsing.owner = TMain;
				role->MagicUsing.IsMagicShowing = false;
				role->MagicUsing.life = magicRLE[role->tool_skill[iSelectSkill-1].id]->bfWidthBitN;
				role->MagicUsing.Back = NULL;
			}
		}
		break;
	case WM_LBUTTONDOWN:
		curpos.x = LOWORD (lParam);
		curpos.y = HIWORD (lParam);
		if(id_newgame == 0)
		{
			if(iMouseType == 11)
			{
				role->FollowID = iMouseInZoetic;
			}
			else if(iMouseType == 8)
			{
			}
			else
			{
				role->FollowID = -1;
			}
			role->moveto(dMap_StartX+curpos.x, dMap_StartY+curpos.y);
			IsMove = true;
		}
		else
		{
			int i = id_newgame >> 12;
			switch(i)
			{
			case 0:
				i = id_newgame&0xfff;
				switch(i)
				{
				case 0x0100:
					IsShowStatusBMP = true;
					break;
				}
				break;
			case 1:
				i = id_newgame&0xfff;
				switch(i)
				{
				case 0x01:
					IsShowStatusBMP = false;
					iStatusW = 0;
					break;
				}
				break;
			case 2:
				iSelect = (id_newgame&0x0f00)>>8;
				switch(iSelect)
				{
				case 0x01:
					break;
				case 0x02:
					i = id_newgame&0x0ff;
					if(i > 0)
					{
						if(i < 0x80)
							UseEquip(i-3);
						else
							RemoveEquip(i&0x7f);
					}
					break;
				case 0x03:
					i = id_newgame&0x0ff;
					if(i > 0)
					{
						i = i - 8;
						moveMagic.id = role->skill[i].id;
						moveMagic.level = role->skill[i].level;
						role->skill[i].id = -1;
						role->skill[i].level = 0;
						IsMoveMagic = true;
					}
					break;
				case 0x04:
					i = id_newgame&0x0ff;
					if(i > 0)
					{
						i = i - 8;
						moveGoods.id = role->medica_goods[i].id;
						moveGoods.iNumber = role->medica_goods[i].iNumber;
						role->medica_goods[i].id = -1;
						role->medica_goods[i].iNumber = 0;
						IsMoveGoods = true;
					}
					break;
				case 0x05:
					i = id_newgame&0x0ff;
					if(i > 0)
					{
						switch(i)
						{
						case 1:
							NewGameSelect = 2 ;	//保存游戏
							break;
						case 2:					//读取游戏
							NewGameSelect = 3 ;
							NewGameOut = true;
							break;
						case 3:
							NewGameSelect = 1 ;	//退出游戏
							NewGameOut = true;
							break;
						}
					}
					break;
				case 0x06:
					break;
				}
				break;
			}
		}
		break;
	case WM_MOUSEMOVE:
		curpos.x = LOWORD (lParam);
		curpos.y = HIWORD (lParam);
		if(curpos.x > SCREEN_WIDTH - 1 )
		{
			curpos.x = SCREEN_WIDTH-1;
			SetCursorPos(curpos.x, curpos.y);
		}
		if(curpos.y > SCREEN_HEIGHT - 1)
		{
			curpos.y = SCREEN_HEIGHT-1;
			SetCursorPos(curpos.x, curpos.y);
		}
		if(IsMove)
		{
		//	role->moveto(dMap_StartX+curpos.x, dMap_StartY+curpos.y);
		}
		else
		{
			if((!IsMoveGoods)&&(!IsMoveMagic))
			{
				JudgeMousePlace( );
				if(id_newgame != 0)
				{
					if(iMouseType != 1)
					{
						cursor = 0;
						PA_SAFE_DELETE(mouseRLE);
						mouseRLE = LoadRleImage("Pic\\cursor\\cursor01.ret");
						cursorT = 4;
						iMouseType = 1;
					}
				}
				else if(iMouseType != 3)
				{
					cursor = 0;
					PA_SAFE_DELETE(mouseRLE);
					mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
					cursorT = 4;
					iMouseType = 3;
				}
			}
		}
		break;
		
	case WM_LBUTTONUP:
		IsMove = false;
		JudgeMousePlace( );
		if(IsMoveGoods)
		{
			IsMoveGoods = false;
			if((id_newgame > 0x1100)&&(id_newgame < 0x1200))
			{
				i = (id_newgame&0xff)-1;
				if(role->tool_goods[i].id != -1)
				{
					for(j = 0; j < MaxMedica_Schlep; j++)
						if(role->medica_goods[j].id == -1)
						{
							role->medica_goods[j].id = role->tool_goods[i].id;
							role->medica_goods[j].iNumber = role->tool_goods[i].iNumber;
							break;
						}

				}
				role->tool_goods[i].id = moveGoods.id;
				role->tool_goods[i].iNumber = moveGoods.iNumber;
			}
			else
			{
				for(j = 0; j < MaxMedica_Schlep; j++)
					if(role->medica_goods[j].id == -1)
					{
						role->medica_goods[j].id = moveGoods.id;
						role->medica_goods[j].iNumber = moveGoods.iNumber;
						break;
					}
			}
		}
		else if(IsMoveMagic)
		{
			IsMoveMagic = false;
			if((id_newgame > 0x1200)&&(id_newgame < 0x1300))
			{
				i = (id_newgame&0xff)-1;
				if(role->tool_skill[i].id != -1)
				{
					for(j = 0; j < MaxSkill_Schlep; j++)
						if(role->skill[j].id == -1)
						{
							role->skill[j].id = role->tool_skill[i].id;
							role->skill[j].level = role->tool_skill[i].level;
							break;
						}

				}
				role->tool_skill[i].id = moveMagic.id;
				role->tool_skill[i].level = moveMagic.level;
			}
			else
			{
				for(j = 0; j < MaxSkill_Schlep; j++)
					if(role->skill[j].id == -1)
					{
						role->skill[j].id = moveMagic.id;
						role->skill[j].level = moveMagic.level;
						break;
					}
			}
		}
		if(id_newgame != 0)
		{
			if(iMouseType != 1)
			{
				cursor = 0;
				PA_SAFE_DELETE(mouseRLE);
				mouseRLE = LoadRleImage("Pic\\cursor\\cursor01.ret");
				cursorT = 4;
				iMouseType = 1;
			}
		}
		else if(iMouseType != 3)
		{
			cursor = 0;
			PA_SAFE_DELETE(mouseRLE);
			mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
			cursorT = 4;
			iMouseType = 3;
		}

    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 1;
}

void NewGameRefreshScreen()
{
	MovRole( );
	MovZoetic( );
	ChangeTheDynamicPic( );
	ChangeAttackTextStatus( );
	ChangeMagicStatus( );
	AddMagicToLink( );
	if(Script->Script != NULL)
		Script->Run( );
	RECT rect1;
	rect1.left = dMap_StartX;
	rect1.top = dMap_StartY;
	rect1.right = rect1.left + SW[SMap];
	rect1.bottom = rect1.top + SH[SMap];

	Map->ShowMap_Surface(rect1, 0, 0);

	rect1.left = dMap_StartX%32;
	rect1.top = dMap_StartY%32;
	rect1.right = rect1.left+SCREEN_WIDTH;
	rect1.bottom = rect1.top+SCREEN_HEIGHT;
	
	FastBlt(0, 0, rect1, pS[SBuffer], pS[SMap], SP[SBuffer], SP[SMap], false, 0);

	rect1.left = dMap_StartX;
	rect1.top = dMap_StartY;
	rect1.bottom = rect1.left + SCREEN_WIDTH;
	rect1.bottom = rect1.top+SCREEN_HEIGHT;
	Map->ShowMap_Obj(rect1, 0, 0);

	//显示主角目的地
	if(role->WalkNumber != -1)
	{
		rect1.left = (role->lFinX-dMap_StartX)-((PurposeRLE->bfWidth/PurposeRLE->bfWidthBitN)>>1) > 0? 0 : dMap_StartX+((PurposeRLE->bfWidth/PurposeRLE->bfWidthBitN)>>1)-role->lFinX;
		rect1.top  = (role->lFinY-dMap_StartY)-PurposeRLE->bfHeight > 0? 0 : dMap_StartY+PurposeRLE->bfHeight-role->lFinY;
		rect1.right = (role->lFinX-dMap_StartX)+((PurposeRLE->bfWidth/PurposeRLE->bfWidthBitN)>>1) > SCREEN_WIDTH?SCREEN_WIDTH+dMap_StartY-((PurposeRLE->bfWidth/PurposeRLE->bfWidthBitN)>>1)-role->lFinX:PurposeRLE->bfWidth/PurposeRLE->bfWidthBitN;
		rect1.bottom = PurposeRLE->bfHeight;
		ShowRleImage((role->lFinX-dMap_StartX)-((PurposeRLE->bfWidth/PurposeRLE->bfWidthBitN)>>1)+rect1.left, (role->lFinY-dMap_StartY)-PurposeRLE->bfHeight+rect1.top, PurposeTimes, 0, rect1, PurposeRLE, pS[SBuffer], SP[SBuffer]);
	}
	else
	{
		PurposeTimes = 0;
	}

	//显示魔法
	MagicIsUsing * magic_Link;  //中介指针
	magic_Link = magic_using;
	while(magic_Link)
	{
		magic_Link->IsMagicShowing = true;
		PlayMagic(magic_Link);
		magic_Link->IsMagicShowing = false;
		magic_Link = magic_Link->Next;
	}
	//显示受攻击文字
	AttackText * Text_Link;
	Text_Link = Attack_Text;
	while(Text_Link)
	{
		Text_Link->IsShowing = true;
		Show_AttackText(Text_Link);
		Text_Link->IsShowing = false;
		Text_Link = Text_Link->Next;
	}

//显示工具栏
	if(IsShowStatusBMP)
	{
		rect1.left = statusBMP->bfWidth-iStatusW;
		rect1.right = statusBMP->bfWidth;
		rect1.top = 0;
		rect1.bottom = statusBMP->bfHeight*(rect1.right-rect1.left)/rect1.right;
		ShowBMPImage(0, SCREEN_HEIGHT-(rect1.bottom-rect1.top), rect1, statusBMP, pS[SBuffer], SP[SBuffer], false);
		if(iStatusW == statusBMP->bfWidth)
		{
			ShowRleImage_NR((SCREEN_WIDTH-lineRLE->bfWidth/lineRLE->bfWidthBitN)>>1, SCREEN_HEIGHT-statusBMP->bfHeight-10, iLineN, 0, lineRLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(SCREEN_WIDTH-arrowRLE->bfWidth/arrowRLE->bfWidthBitN, SCREEN_HEIGHT-statusBMP->bfHeight,iArrowN, 0, arrowRLE, pS[SBuffer], SP[SBuffer]);
			ShowRoleInfo( );
		}
	}
	else
	{
		ShowRleImage_NR(0, SCREEN_HEIGHT-arrowRLE->bfHeight/arrowRLE->bfHeightBitN,iArrowN+12, 0, arrowRLE, pS[SBuffer], SP[SBuffer]);
	}
	//当保存游戏时,将当前屏幕生成小图象
	if(NewGameSelect == 2)
	{
		RECT srect, drect;
		srect.left = dMap_StartX > 0? role->x - dMap_StartX - (SCREEN_WIDTH>>2) : 0;
		srect.top =	 dMap_StartY > 0? role->y - dMap_StartY - (SCREEN_HEIGHT>>2) : 0;
		srect.right = srect.left + (SCREEN_WIDTH>>1);
		if(srect.right > SCREEN_WIDTH)
		{
			srect.right = SCREEN_WIDTH;
			srect.left = srect.right - (SCREEN_WIDTH>>1);
		}
		srect.bottom = srect.top + (SCREEN_HEIGHT>>1);
		if(srect.bottom > SCREEN_HEIGHT)
		{
			srect.bottom = SCREEN_HEIGHT;
			srect.top = srect.bottom - (SCREEN_HEIGHT>>1);
		}
		drect = MakeRect(0, 0, SW[SGameImage], SH[SGameImage]);
		DDS[SGameImage]->Blt(&drect, DDS[SBuffer], &srect, DDBLT_WAIT, NULL);
		NewGameOut = true;
		return ;
	}
	long lW, lH;
//显示主菜单
	if((IsShowSelect)&&(GameStatus == GAME_NORMAL))
	{
		lW = (SCREEN_WIDTH-newgame_selectRLE->bfWidth)>>1;
		lH = (SCREEN_HEIGHT-statusBMP->bfHeight-newgame_selectRLE->bfHeight)>>1;
		ShowRleImage_NR(lW, lH,0,0,newgame_selectRLE, pS[SBuffer], SP[SBuffer]);
		ShowRleImage_NR(lW+57+(iSelect - 1)*46, lH+26,(iSelect-1),0,newgame_titleRLE, pS[SBuffer], SP[SBuffer]);
		ShowSelectInfo(lW, lH);
	}
//显示鼠标
	if(IsMoveGoods)
	{
		lW = (goodsRLE->bfWidth/goodsRLE->bfWidthBitN)>>1;
		lH = (goodsRLE->bfHeight/goodsRLE->bfHeightBitN)>>1;
		rect1.left = curpos.x - lW > 0? 0 : lW - curpos.x;
		rect1.top = curpos.y - lH > 0? 0 : lH - curpos.y;
		rect1.right = curpos.x+lW > SCREEN_WIDTH?SCREEN_WIDTH-curpos.x+lW:lW<<1;
		rect1.bottom = curpos.y+lH > SCREEN_HEIGHT?SCREEN_HEIGHT-curpos.y+lH:lH<<1;
		ShowRleImage(curpos.x-(lW-rect1.left), curpos.y-(lH-rect1.top), moveGoods.id, 0, rect1, goodsRLE, pS[SBuffer], SP[SBuffer]);
	}
	else if(IsMoveMagic)
	{
		lW = (magicRLE_tool->bfWidth/magicRLE_tool->bfWidthBitN)>>1;
		lH = (magicRLE_tool->bfHeight/magicRLE_tool->bfHeightBitN)>>1;
		rect1.left = curpos.x - lW > 0? 0 : lW - curpos.x;
		rect1.top = curpos.y - lH > 0? 0 : lH - curpos.y;
		rect1.right = curpos.x+lW > SCREEN_WIDTH?SCREEN_WIDTH-curpos.x+lW:lW<<1;
		rect1.bottom = curpos.y+lH > SCREEN_HEIGHT?SCREEN_HEIGHT-curpos.y+lH:lH<<1;
		ShowRleImage(curpos.x-(lW-rect1.left), curpos.y-(lH-rect1.top), moveMagic.id, 0, rect1, magicRLE_tool, pS[SBuffer], SP[SBuffer]);
	}
	lW = mouseRLE->bfWidth/mouseRLE->bfWidthBitN;
	lH = mouseRLE->bfHeight/mouseRLE->bfHeightBitN;
	switch(iMouseType)
	{
	case 0:
	case 1:
	case 2:
		rect1.left = 0;
		rect1.top  = 0;
		rect1.right = curpos.x+lW > SCREEN_WIDTH?SCREEN_WIDTH-curpos.x:lW;
		rect1.bottom = curpos.y+lH > SCREEN_HEIGHT?SCREEN_HEIGHT-curpos.y:lH;
		ShowRleImage(curpos.x, curpos.y, cursor, 0, rect1, mouseRLE, pS[SBuffer], SP[SBuffer]);
		break;
	case 3:
	case 8:
	case 11:
		rect1.left = curpos.x-(lW>>1) > 0? 0 : (lW>>1)-curpos.x;
		rect1.top  = curpos.y-(lH>>1) > 0? 0 : (lH>>1)-curpos.y;
		rect1.right = curpos.x+(lW>>1) > SCREEN_WIDTH?SCREEN_WIDTH-curpos.x+(lW>>1):lW;
		rect1.bottom = curpos.y+(lH>>1) > SCREEN_HEIGHT?SCREEN_HEIGHT-curpos.y+(lH>>1):lH;
		ShowRleImage(curpos.x-((lW>>1)-rect1.left), curpos.y-((lH>>1)-rect1.top), cursor, 0, rect1, mouseRLE, pS[SBuffer], SP[SBuffer]);
		break;
	}
	IsMouseOnSomeone( );
	UpdateScreen();
}

void CALLBACK NewGameTimer(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
	static DWORD dStarttime = timeGetTime();
	static fps = 0;
	static int tt=100;
	int i;
	tt++;
	time++;
	if(tt%4 == 0)
		iLineN = (iLineN+1)%7;
	if(tt%2 == 0)
		iArrowN = (iArrowN+1)%12;
	if(iStatusW < statusBMP->bfWidth)
	{
		iStatusW += 10;
		if(iStatusW > statusBMP->bfWidth)
			iStatusW = statusBMP->bfWidth;
	}

//----------------------------改变地图起始坐标--------------------
	if(GameStatus == GAME_NORMAL)
	{
		dMap_StartX = role->dx-(SCREEN_WIDTH>>1);
		dMap_StartY = role->dy-(SCREEN_HEIGHT>>1);
		if(dMap_StartX < 0)
			dMap_StartX = 0;
		if(dMap_StartY < 0)
			dMap_StartY = 0;
		if(dMap_StartX+SCREEN_WIDTH > (Map->pHeader.nWidth<<5))
			dMap_StartX = (Map->pHeader.nWidth<<5) - SCREEN_WIDTH;
		if(dMap_StartY+SCREEN_HEIGHT > (Map->pHeader.nHeight<<5))
			dMap_StartY = (Map->pHeader.nHeight<<5) - SCREEN_HEIGHT;
	}
	if(timeGetTime() - dStarttime < 1000)
		fps++;
	else
	{
		iTimes = fps;
		fps = 0;
		dStarttime = timeGetTime();
	}
	for(i = 0; i < (int)Zoetic->ZoeticHeader.nMagicN; i++)
		if((Zoetic->ZoeticLink[i].health <= 0)&&(Zoetic->MainStatus[i] != AWAY))
			Zoetic->MainStatus[i] = DIE;
	if(role->health <= 0)
		role->MainStatus = DIE;
}

void ShowRoleInfo( )
{
	char info[20];
	char info1[20];
	int	 iPercent, i;
	RECT rect;
	int  iStatusY = SCREEN_HEIGHT-statusBMP->bfHeight;
	HDC	 hdc;
	CFont cFont;
	DDS[SBuffer]->GetDC(&hdc);
	cFont.UseFont(hdc,DCF_USERDEFINE, 12);

	wsprintf(info,"%3d",role->health);
	ShowText(hdc, 140,iStatusY+20, RGB(125,0,0), info);
	wsprintf(info,"%3d",role->MaxHealth);
	ShowText(hdc, 164,iStatusY+20, RGB(125,0,0), info);
	wsprintf(info,"%3d",role->energy);
	ShowText(hdc, 235,iStatusY+20, RGB(0,125,0), info);
	wsprintf(info,"%3d",role->MaxEnergy);
	ShowText(hdc, 258,iStatusY+20, RGB(0,125,0), info);
	wsprintf(info,"%3d",role->vigor);
	ShowText(hdc, 328,iStatusY+20, RGB(0,0,125), info);
	wsprintf(info,"%3d",role->MaxVigor);
	ShowText(hdc, 352,iStatusY+20, RGB(0,0,125), info);

	wsprintf(info,"%5d",role->x);
	ShowText(hdc, 172,iStatusY+72, RGB(0,0,0), info);
	wsprintf(info,"%5d",role->y);
	ShowText(hdc, 199,iStatusY+72, RGB(0,0,0), info);
	wsprintf(info,"%3d",role->z);
	ShowText(hdc, 345,iStatusY+72, RGB(0,0,0), info);
	cFont.RestoreFont(hdc);
	cFont.UseFont(hdc,DCF_USERDEFINE, 20);
	if(role->FollowID == -1)
		strcpy(info, "没有跟随人");
	else
		strcpy(info, Zoetic->ZoeticLink[role->FollowID].dName);
	ShowText(hdc, 202,iStatusY+47, RGB(128,0,0), info);
	
	iPercent = (int)(role->health*100/role->MaxHealth);
	rect.left = 0;
	rect.top = 100 - iPercent;
	rect.right = 47;
	rect.bottom = 100;
	ShowRleImage(39, iStatusY+rect.top, 0, 0, rect, healthRLE, pS[SBuffer], SP[SBuffer]);
	
	iPercent = (int)(role->energy*100/role->MaxEnergy);
	rect.left = 0;
	rect.top = 100 - iPercent;
	rect.right = 47;
	rect.bottom = 100;
	ShowRleImage(718, iStatusY+rect.top, 0, 0, rect, energyRLE, pS[SBuffer], SP[SBuffer]);
	
	iPercent = (int)(role->vigor*100/role->MaxVigor);
	rect.left = 0;
	rect.top = 100 - iPercent;
	rect.right = 47;
	rect.bottom = 100;
	ShowRleImage(377, iStatusY+rect.top, 0, 0, rect, vigorRLE, pS[SBuffer], SP[SBuffer]);

	//在工具栏中显示物品
	cFont.RestoreFont(hdc);
	cFont.UseFont(hdc,DCF_USERDEFINE, 12);
	for(i = 0; i < 6; i++)
	{
		if(role->tool_goods[i].id != -1)
		{
			ShowRleImage_NR(490+37*i, iStatusY+12, role->tool_goods[i].id, 0, goodsRLE, pS[SBuffer], SP[SBuffer]);
			itoa(i+1, info, 10);
			ShowText(hdc, 493+37*i,iStatusY+14, RGB(255,255,255), info);
			itoa(role->tool_goods[i].iNumber, info, 10);
			ShowText(hdc, 513+37*i,iStatusY+32, RGB(128,128,255), info);
		}
		else
		{
			itoa(i+1, info, 10);
			ShowText(hdc, 493+37*i,iStatusY+14, RGB(255,0,0), info);		
		}
	}
	//在工具栏中显示技能
	for(i = 0; i < 6; i++)
	{
		if(role->tool_skill[i].id != -1)
		{
			ShowRleImage_NR(490+37*i, iStatusY+56, role->tool_skill[i].id, 0, magicRLE_tool, pS[SBuffer], SP[SBuffer]);
			itoa(role->tool_skill[i].level, info, 10);
			ShowText(hdc, 513+37*i,iStatusY+56, RGB(128,128,255), info);
			itoa(i+1, info1, 10);
			strcpy(info, "F");
			strcat(info, info1);
			if(i == iSelectSkill-1)
			{
				ShowText(hdc, 493+37*i,iStatusY+58, RGB(255,0,0), info);
			}
			else
				ShowText(hdc, 493+37*i,iStatusY+58, RGB(0,255,0), info);
		}
		else
		{
			itoa(i+1, info1, 10);
			strcpy(info, "F");
			strcat(info, info1);
			ShowText(hdc, 493+37*i,iStatusY+58, RGB(255,255,255), info);
		}
	}
	cFont.RestoreFont(hdc);	
	DDS[SBuffer]->ReleaseDC(hdc);
}

void JudgeMousePlace( )
{
	long lW, lH;
	int x, y;
	id_newgame = 0;
		if(IsShowStatusBMP)
		{
			//工具栏中的事件由0x1000~0x1fff
			lH = SCREEN_HEIGHT-statusBMP->bfHeight;
			if(curpos.y > lH)
			{
				id_newgame = 0x1000;
				if((curpos.x > (long)(SCREEN_WIDTH-arrowRLE->bfWidth/arrowRLE->bfWidthBitN))&&(curpos.y < (long)(lH + arrowRLE->bfHeight/arrowRLE->bfHeightBitN)))
				{
					//缩小工具栏为:0x1001
					id_newgame |= 0x01;
				}
				else if((curpos.x > 488)&&(curpos.y > lH+11)&&(curpos.x < 523)&&(curpos.y < lH + 44))
					id_newgame |= 0x101;
				else if((curpos.x > 525)&&(curpos.y > lH+11)&&(curpos.x < 560)&&(curpos.y < lH + 44))
					id_newgame |= 0x102;
				else if((curpos.x > 562)&&(curpos.y > lH+11)&&(curpos.x < 597)&&(curpos.y < lH + 44))
					id_newgame |= 0x103;
				else if((curpos.x > 599)&&(curpos.y > lH+11)&&(curpos.x < 634)&&(curpos.y < lH + 44))
					id_newgame |= 0x104;
				else if((curpos.x > 626)&&(curpos.y > lH+11)&&(curpos.x < 671)&&(curpos.y < lH + 44))
					id_newgame |= 0x105;
				else if((curpos.x > 673)&&(curpos.y > lH+11)&&(curpos.x < 708)&&(curpos.y < lH + 44))
					id_newgame |= 0x106;
				else if((curpos.x > 489)&&(curpos.y > lH+55)&&(curpos.x < 524)&&(curpos.y < lH + 87))
					id_newgame |= 0x201;
				else if((curpos.x > 526)&&(curpos.y > lH+55)&&(curpos.x < 561)&&(curpos.y < lH + 87))
					id_newgame |= 0x202;
				else if((curpos.x > 563)&&(curpos.y > lH+55)&&(curpos.x < 598)&&(curpos.y < lH + 87))
					id_newgame |= 0x203;
				else if((curpos.x > 600)&&(curpos.y > lH+55)&&(curpos.x < 635)&&(curpos.y < lH + 87))
					id_newgame |= 0x204;
				else if((curpos.x > 627)&&(curpos.y > lH+55)&&(curpos.x < 672)&&(curpos.y < lH + 87))
					id_newgame |= 0x205;
				else if((curpos.x > 674)&&(curpos.y > lH+55)&&(curpos.x < 709)&&(curpos.y < lH + 87))
					id_newgame |= 0x206;
			}
		}
		else
		{
			//放大工具栏为:0x100;
			if((curpos.x < (long)(arrowRLE->bfWidth/arrowRLE->bfWidthBitN))&&(curpos.y > (long)(SCREEN_HEIGHT-arrowRLE->bfHeight/arrowRLE->bfHeightBitN)))
			{
				id_newgame = 0x100;
			}
		}
		//选择栏的事件由0x2000~0x2fff
		if(IsShowSelect)
		{
			lW = (SCREEN_WIDTH-newgame_selectRLE->bfWidth)>>1;
			lH = (SCREEN_HEIGHT-statusBMP->bfHeight-newgame_selectRLE->bfHeight)>>1;
			if((curpos.y > lH)&&(curpos.y < lH + newgame_selectRLE->bfHeight)&&(curpos.x > lW+45)&&(curpos.x < lW + newgame_selectRLE->bfWidth-45))
			{
				id_newgame = 0x2000;
					switch(iSelect)
					{
					case 1:
						if((curpos.y > lH+30)&&(curpos.y < lH+60))
						{
							if((curpos.x > lW+112)&&(curpos.x < lW+155))
								id_newgame |= 0x0200;
							else if((curpos.x > lW+154)&&(curpos.x < lW+203))
								id_newgame |= 0x0300;
							else if((curpos.x > lW+202)&&(curpos.x < lW+250))
								id_newgame |= 0x0400;
							else if((curpos.x > lW+249)&&(curpos.x < lW+297))
								id_newgame |= 0x0500;
							else if((curpos.x > lW+296)&&(curpos.x < lW+345))
								id_newgame |= 0x0600;
							else
								id_newgame |= 0x0100;
						}
						else
						{
							id_newgame |= 0x0100;
						}
						break;
					case 2:	
						if((curpos.y > lH+30)&&(curpos.y < lH+60))
						{
							if((curpos.x > lW+60)&&(curpos.x < lW+103))
								id_newgame |= 0x0100;
							else if((curpos.x > lW+158)&&(curpos.x < lW+203))
								id_newgame |= 0x0300;
							else if((curpos.x > lW+202)&&(curpos.x < lW+250))
								id_newgame |= 0x0400;
							else if((curpos.x > lW+249)&&(curpos.x < lW+297))
								id_newgame |= 0x0500;
							else if((curpos.x > lW+296)&&(curpos.x < lW+345))
								id_newgame |= 0x0600;
							else
								id_newgame |= 0x0200;
						}
						else
						{
							id_newgame |= 0x0200;
							if((curpos.x > lW+59)&&(curpos.x < lW+155)&&(curpos.y > lH+76)&&(curpos.y < lH+224))
							{
								x = (curpos.x - lW - 59)>>5;
								y = (curpos.y - lH - 76)/37;
								if(role->equip_goods[y*3+x].iNumber != 0)
								{
									id_newgame |= (y+1)*3+x;
								}
							}
							else if((curpos.y > lH+74)&&(curpos.y < lH+106))
							{
								if((curpos.x > lW+228)&&(curpos.x < lW+260)&&(role->equiped[0] != -1))
										id_newgame |= 0x80;
								else if((curpos.x > lW+268)&&(curpos.x < lW+300)&&(role->equiped[1] != -1))
										id_newgame |= 0x81;
								else if((curpos.x > lW+308)&&(curpos.x < lW+340)&&(role->equiped[2] != -1))
										id_newgame |= 0x82;
							}
							else if((curpos.y > lH+119)&&(curpos.y < lH+151))
							{
								if((curpos.x > lW+228)&&(curpos.x < lW+260)&&(role->equiped[3] != -1))
										id_newgame |= 0x83;
								else if((curpos.x > lW+268)&&(curpos.x < lW+300)&&(role->equiped[4] != -1))
										id_newgame |= 0x84;
								else if((curpos.x > lW+308)&&(curpos.x < lW+340)&&(role->equiped[5] != -1))
										id_newgame |= 0x85;
							}
						}
						break;
					case 3:
						if((curpos.y > lH+30)&&(curpos.y < lH+60))
						{
							if((curpos.x > lW+60)&&(curpos.x < lW+107))
								id_newgame |= 0x0100;
							else if((curpos.x > lW+106)&&(curpos.x < lW+150))
								id_newgame |= 0x0200;
							else if((curpos.x > lW+206)&&(curpos.x < lW+250))
								id_newgame |= 0x0400;
							else if((curpos.x > lW+249)&&(curpos.x < lW+297))
								id_newgame |= 0x0500;
							else if((curpos.x > lW+296)&&(curpos.x < lW+345))
								id_newgame |= 0x0600;
							else
								id_newgame |= 0x0300;
						}
						else
						{
							id_newgame |= 0x0300;
							if((curpos.x > lW+59)&&(curpos.x < lW+347)&&(curpos.y > lH+63)&&(curpos.y < lH+243))
							{
								x = (curpos.x - lW - 59)/36;
								y = (curpos.y - lH - 63)/36;
								if(role->medica_goods[y*8+x].iNumber != 0)
								{
									id_newgame |= (y+1)*8+x;
								}
							}
						}
						break;
					case 4:
						if((curpos.y > lH+30)&&(curpos.y < lH+60))
						{
							if((curpos.x > lW+60)&&(curpos.x < lW+107))
								id_newgame |= 0x0100;
							else if((curpos.x > lW+106)&&(curpos.x < lW+155))
								id_newgame |= 0x0200;
							else if((curpos.x > lW+154)&&(curpos.x < lW+198))
								id_newgame |= 0x0300;
							else if((curpos.x > lW+253)&&(curpos.x < lW+297))
								id_newgame |= 0x0500;
							else if((curpos.x > lW+296)&&(curpos.x < lW+345))
								id_newgame |= 0x0600;
							else
								id_newgame |= 0x0400;
						}
						else
						{
							id_newgame |= 0x0400;
							if((curpos.x > lW+59)&&(curpos.x < lW+347)&&(curpos.y > lH+63)&&(curpos.y < lH+243))
							{
								x = (curpos.x - lW - 59)/36;
								y = (curpos.y - lH - 63)/36;
								if(role->medica_goods[y*8+x].iNumber != 0)
								{
									id_newgame |= (y+1)*8+x;
								}
							}
						}
							break;
					case 5:
						if((curpos.y > lH+30)&&(curpos.y < lH+60))
						{
							if((curpos.x > lW+60)&&(curpos.x < lW+107))
								id_newgame |= 0x0100;
							else if((curpos.x > lW+106)&&(curpos.x < lW+155))
								id_newgame |= 0x0200;
							else if((curpos.x > lW+154)&&(curpos.x < lW+203))
								id_newgame |= 0x0300;
							else if((curpos.x > lW+202)&&(curpos.x < lW+246))
								id_newgame |= 0x0400;
							else if((curpos.x > lW+300)&&(curpos.x < lW+345))
								id_newgame |= 0x0600;
							else
								id_newgame |= 0x0500;
						}
						else
						{
							id_newgame |= 0x0500;
							if((curpos.x > lW+77)&&(curpos.x < lW+329))
							{
								if((curpos.y > lH+81)&&(curpos.y < lH+161))
								{
									id_newgame |= 0x01;
								}
								else if((curpos.y > lH+171)&&(curpos.y < lH+251))
								{
									id_newgame |= 0x02;
								}
								else if((curpos.y > lH+261)&&(curpos.y < lH+341))
								{
									id_newgame |= 0x03;
								}
							}
						}
						break;
					case 6:
						if((curpos.y > lH+30)&&(curpos.y < lH+60))
						{
							if((curpos.x > lW+60)&&(curpos.x < lW+107))
								id_newgame |= 0x0100;
							else if((curpos.x > lW+106)&&(curpos.x < lW+155))
								id_newgame |= 0x0200;
							else if((curpos.x > lW+154)&&(curpos.x < lW+203))
								id_newgame |= 0x0300;
							else if((curpos.x > lW+202)&&(curpos.x < lW+250))
								id_newgame |= 0x0400;
							else if((curpos.x > lW+249)&&(curpos.x < lW+293))
								id_newgame |= 0x0500;
							else
								id_newgame |= 0x0600;
						}
						else
						{
							id_newgame |= 0x0600;
						}
						break;
					}
			}
		}
}

void ShowSelectInfo(long lW, long lH)
{
	int sm = role->FootStatus;
	char info[255];
	char info1[10];
	char* pInfo;
	int	 i, j, k;
	RECT rect;
	HDC	 hdc;
	CFont cFont;
	

	if (sm==-1)
		sm=0;
	switch(iSelect)
	{
	case 1:
		ShowRleImage_NR(lW+76, lH+80, (role->type<<2)+sm, role->face, Role_Pic, pS[SBuffer], SP[SBuffer]);
		DDS[SBuffer]->GetDC(&hdc);
		cFont.UseFont(hdc,DCF_USERDEFINE, 20);
		strcpy(info, "等级: ");
		wsprintf(info1,"%4d",role->level);
		strcat(info, info1);
		ShowText(hdc, lW+180, lH+70, RGB(0,255,255), info);

		strcpy(info, "生命:");
		wsprintf(info1,"%3d",role->health);
		strcat(info, info1);
		strcat(info, " / ");
		wsprintf(info1,"%3d",role->MaxHealth);
		strcat(info, info1);
		ShowText(hdc, lW+180, lH+95, RGB(255,0,0), info);

		strcpy(info, "内力:");
		wsprintf(info1,"%3d",role->energy);
		strcat(info, info1);
		strcat(info, " / ");
		wsprintf(info1,"%3d",role->MaxEnergy);
		strcat(info, info1);
		ShowText(hdc, lW+180, lH+120, RGB(0,255,0), info);

		strcpy(info, "精力:");
		wsprintf(info1,"%3d",role->vigor);
		strcat(info, info1);
		strcat(info, " / ");
		wsprintf(info1,"%3d",role->MaxVigor);
		strcat(info, info1);
		ShowText(hdc, lW+180, lH+145, RGB(0,0,255), info);

		strcpy(info, "攻击力:");
		wsprintf(info1,"%3d",role->attack);
		strcat(info, info1);
		strcat(info, " 攻击速度:");
		wsprintf(info1,"%3d",role->v);
		strcat(info, info1);
		ShowText(hdc, lW+70, lH+190, RGB(255,255,255), info);

		strcpy(info, "防御力:");
		wsprintf(info1,"%3d",role->defend);
		strcat(info, info1);
		strcat(info, " 行走速度:");
		wsprintf(info1,"%3d",role->speed);
		strcat(info, info1);
		ShowText(hdc, lW+70, lH+220, RGB(255,255,255), info);

		strcpy(info, "敏  捷:");
		wsprintf(info1,"%3d",role->agility);
		strcat(info, info1);
		strcat(info, " 名    望:");
		wsprintf(info1,"%3d",role->reputation);
		strcat(info, info1);
		ShowText(hdc, lW+70, lH+250, RGB(255,255,255), info);

		strcpy(info, "实战经验: ");
		wsprintf(info1,"%8ld",role->experiment);
		strcat(info, info1);
		ShowText(hdc, lW+70, lH+280, RGB(255,255,0), info);
		
		strcpy(info, "升级经验: ");
		wsprintf(info1,"%8ld",role->MaxExperiment);
		strcat(info, info1);
		ShowText(hdc, lW+70, lH+310, RGB(255,255,0), info);



		cFont.RestoreFont(hdc);
		DDS[SBuffer]->ReleaseDC(hdc);

		break;
	case 2:
		//显示装备架
		rect.left = 0;
		rect.top = 0;
		rect.right = equip_shelfBMP->bfWidth;
		rect.bottom = equip_shelfBMP->bfHeight;
		ShowBMPImage(lW+59, lH+63, rect, equip_shelfBMP, pS[SBuffer], SP[SBuffer], false);
		//显示装备说明框
		rect.right = goods_explainBMP->bfWidth;
		rect.bottom = goods_explainBMP->bfHeight;
		ShowBMPImage(lW+59, lH+270, rect, goods_explainBMP, pS[SBuffer], SP[SBuffer], false);
		//显示人物装备情况
		ShowRleImage_NR(lW+167, lH+63, 0, 0, man_equipRLE, pS[SBuffer], SP[SBuffer]);
		for(i = 0; i < 6; i++)
		{
			if(role->equiped[i] != -1)
			{
				ShowRleImage_NR(lW+228+((i%3)<<5)+((i%3)<<3), lH+74+((i/3)<<5)+((i/3)<<3)+((i/3)<<2)+(i/3), role->equiped[i], 0, goodsRLE, pS[SBuffer], SP[SBuffer]);
			}
		}
		//显示人物信息
		DDS[SBuffer]->GetDC(&hdc);
		cFont.UseFont(hdc,DCF_USERDEFINE, 15);
		//最大生命
		wsprintf(info,"%3d",role->MaxHealth);
		ShowText(hdc, lW+217, lH+165, RGB(255,0,0), info);
		//最大内力
		wsprintf(info,"%3d",role->MaxEnergy);
		ShowText(hdc, lW+305, lH+165, RGB(0,255,0), info);
		//最大精力
		wsprintf(info,"%3d",role->MaxVigor);
		ShowText(hdc, lW+217, lH+180, RGB(0,0,255), info);
		//敏捷
		wsprintf(info,"%3d",role->agility);
		ShowText(hdc, lW+305, lH+180, RGB(0,255,128), info);
		//攻击速度
		wsprintf(info,"%3d",role->v);
		ShowText(hdc, lW+247, lH+195, RGB(0,0,255), info);
		//行走速度
		wsprintf(info,"%3d",role->speed);
		ShowText(hdc, lW+247, lH+210, RGB(0,255,128), info);
		//防御力
		wsprintf(info,"%3d",role->defend);
		ShowText(hdc, lW+232, lH+225, RGB(0,255,0), info);
		//攻击力
		wsprintf(info,"%3d",role->attack);
		ShowText(hdc, lW+317, lH+225, RGB(255,0,0), info);
		//名望
		wsprintf(info,"%3d",role->reputation);
		ShowText(hdc, lW+217, lH+240, RGB(255,255,0), info);

		cFont.RestoreFont(hdc);
		DDS[SBuffer]->ReleaseDC(hdc);


		//显示装备
		for(i = 0; i < MaxEquip_Schlep; i++)
			if((role->equip_goods[i].id != -1)&&(role->equip_goods[i].iNumber != 0))
			{
				ShowRleImage_NR(lW+59+((i%3)<<5), lH+76+((i/3)*37), role->equip_goods[i].id, 0, goodsRLE, pS[SBuffer], SP[SBuffer]);
			}
		DDS[SBuffer]->GetDC(&hdc);
		cFont.UseFont(hdc,DCF_USERDEFINE, 10);
		for(i = 0; i < MaxEquip_Schlep; i++)
		{
			if((role->equip_goods[i].id != -1)&&(role->equip_goods[i].iNumber != 0))
			{
				wsprintf(info,"%3d",role->equip_goods[i].iNumber);
				ShowText(hdc, lW+80+((i%3)<<5), lH+96+((i/3)*37), RGB(255,255,255), info);
			}
		}
		cFont.RestoreFont(hdc);
		DDS[SBuffer]->ReleaseDC(hdc);

		if((id_newgame > 0x2200)&&(id_newgame < 0x2300))
		{
			i = id_newgame&0x0ff;
			if(i < 0x80)
			{
				i = i - 3;
				if((role->equip_goods[i].id != -1)&&(role->equip_goods[i].iNumber != 0))
				{
					ShowRleImage_NR(lW+59+((i%3)<<5), lH+76+((i/3)<<5)+((i/3)<<2)+(i/3), 0, 0, goods_selectedRLE, pS[SBuffer], SP[SBuffer]);
					DDS[SBuffer]->GetDC(&hdc);
					cFont.UseFont(hdc,DCF_USERDEFINE, 15);
					j = 0;
					pInfo = (char *)Goods->Goods[role->equip_goods[i].id].wInfo;
					info[j] = pInfo[j];
					while((pInfo[j] != -93)||(pInfo[j+1] != -70))
					{
						j++;
						info[j] = pInfo[j];
					}
					k = j+1;
					info[k] = pInfo[k];
					k ++;
					info[k] = '\0';
					ShowText(hdc, lW+65, lH+276, RGB(0,0,0), info);
					j = 0;
					info[j] = pInfo[k];
					while(info[j] != '\0')
					{
						j++;
						info[j] = pInfo[k+j];
					}
					ShowText(hdc, lW+65, lH+300, RGB(0,0,0), info);
					cFont.RestoreFont(hdc);
					DDS[SBuffer]->ReleaseDC(hdc);
				}
			}
			else
			{
				i &= 0x7f;
				if(role->equiped[i] != -1)
				{
					ShowRleImage_NR(lW+228+((i%3)<<5)+((i%3)<<3), lH+74+((i/3)<<5)+((i/3)<<3)+((i/3)<<2)+(i/3), 0, 0, goods_selectedRLE, pS[SBuffer], SP[SBuffer]);
					DDS[SBuffer]->GetDC(&hdc);
					cFont.UseFont(hdc,DCF_USERDEFINE, 15);
					j = 0;
					pInfo = (char *)Goods->Goods[role->equiped[i]].wInfo;
					info[j] = pInfo[j];
					while((pInfo[j] != -93)||(pInfo[j+1] != -70))
					{
						j++;
						info[j] = pInfo[j];
					}
					k = j+1;
					info[k] = pInfo[k];
					k ++;
					info[k] = '\0';
					ShowText(hdc, lW+65, lH+276, RGB(0,0,0), info);
					j = 0;
					info[j] = pInfo[k];
					while(info[j] != '\0')
					{
						j++;
						info[j] = pInfo[k+j];
					}
					ShowText(hdc, lW+65, lH+300, RGB(0,0,0), info);
					cFont.RestoreFont(hdc);
					DDS[SBuffer]->ReleaseDC(hdc);
				}
			}
		}
		break;
	case 3:
		//画技能架
		for(i = 0; i < 6; i++)
			DrawLine(DDS[SBuffer],lW+59,lH+69+(i<<5)+(i<<2),lW+345,lH+69+(i<<5)+(i<<2),RGB(128,128,128),3);
		for(i = 0; i < 7; i++)
			DrawLine(DDS[SBuffer],lW+91+(i<<5)+(i<<2),lH+75,lW+91+(i<<5)+(i<<2),lH+247,RGB(128,128,128),3);
		//显示技能说明框
		rect.left = 0;
		rect.top = 0;
		rect.right = goods_explainBMP->bfWidth;
		rect.bottom = goods_explainBMP->bfHeight;
		ShowBMPImage(lW+59, lH+270, rect, goods_explainBMP, pS[SBuffer], SP[SBuffer], false);
		//显示技能
		for(i = 0; i < MaxSkill_Schlep; i++)
			if((role->skill[i].id != -1)&&(role->skill[i].level != 0))
			{
				ShowRleImage_NR(lW+59+((i&0x7)<<5)+((i&0x7)<<2), lH+72+(((i>>3)<<5)+((i>>3)<<2)), role->skill[i].id, 0, magicRLE_tool, pS[SBuffer], SP[SBuffer]);
			}

		DDS[SBuffer]->GetDC(&hdc);
		cFont.UseFont(hdc,DCF_USERDEFINE, 10);
		for(i = 0; i < MaxSkill_Schlep; i++)
		{
			if((role->skill[i].id != -1)&&(role->skill[i].level != 0))
			{
				wsprintf(info,"%3d",role->skill[i].level);
				ShowText(hdc, lW+75+((i&0x7)<<5)+((i&0x7)<<2), lH+92+(((i>>3)<<5)+((i>>3)<<2)), RGB(255,255,255), info);
			}
		}
		cFont.RestoreFont(hdc);
		DDS[SBuffer]->ReleaseDC(hdc);

		if((id_newgame > 0x2300)&&(id_newgame < 0x2400))
		{
			i = id_newgame&0x0ff;
			i = i - 8;
			if((role->skill[i].id != -1)&&(role->skill[i].level != 0))
			{
				ShowRleImage_NR(lW+59+((i&0x7)<<5)+((i&0x7)<<2), lH+72+(((i>>3)<<5)+((i>>3)<<2)), 0, 0, goods_selectedRLE, pS[SBuffer], SP[SBuffer]);
				DDS[SBuffer]->GetDC(&hdc);
				cFont.UseFont(hdc,DCF_USERDEFINE, 15);
				j = 0;
				pInfo = (char *)Magic->Magic[role->skill[i].id].wInfo;
				info[j] = pInfo[j];
				while((pInfo[j] != -93)||(pInfo[j+1] != -70))
				{
					j++;
					info[j] = pInfo[j];
				}
				k = j+1;
				info[k] = pInfo[k];
				k ++;
				info[k] = '\0';
				ShowText(hdc, lW+65, lH+276, RGB(0,0,0), info);
				j = 0;
				info[j] = pInfo[k];
				while(info[j] != '\0')
				{
					j++;
					info[j] = pInfo[k+j];
				}
				ShowText(hdc, lW+65, lH+300, RGB(0,0,0), info);
				cFont.RestoreFont(hdc);
				DDS[SBuffer]->ReleaseDC(hdc);
			}
		}
		break;
	case 4:
		//显示物品架
		rect.left = 0;
		rect.top = 0;
		rect.right = medica_shelfBMP->bfWidth;
		rect.bottom = medica_shelfBMP->bfHeight;
		ShowBMPImage(lW+59, lH+70, rect, medica_shelfBMP, pS[SBuffer], SP[SBuffer], false);
		//显示物品说明框
		rect.right = goods_explainBMP->bfWidth;
		rect.bottom = goods_explainBMP->bfHeight;
		ShowBMPImage(lW+59, lH+270, rect, goods_explainBMP, pS[SBuffer], SP[SBuffer], false);
		//显示物品
		for(i = 0; i < MaxMedica_Schlep; i++)
			if((role->medica_goods[i].id != -1)&&(role->medica_goods[i].iNumber != 0))
			{
				ShowRleImage_NR(lW+59+((i&0x7)<<5)+((i&0x7)<<2), lH+72+(((i>>3)<<5)+((i>>3)<<2)), role->medica_goods[i].id, 0, goodsRLE, pS[SBuffer], SP[SBuffer]);
			}
		DDS[SBuffer]->GetDC(&hdc);
		cFont.UseFont(hdc,DCF_USERDEFINE, 10);
		for(i = 0; i < MaxMedica_Schlep; i++)
		{
			if((role->medica_goods[i].id != -1)&&(role->medica_goods[i].iNumber != 0))
			{
				wsprintf(info,"%3d",role->medica_goods[i].iNumber);
				ShowText(hdc, lW+80+((i&0x7)<<5)+((i&0x7)<<2), lH+92+(((i>>3)<<5)+((i>>3)<<2)), RGB(255,255,255), info);
			}
		}
		cFont.RestoreFont(hdc);
		DDS[SBuffer]->ReleaseDC(hdc);

		if((id_newgame > 0x2400)&&(id_newgame < 0x2500))
		{
			i = id_newgame&0x0ff;
			i = i - 8;
			if((role->medica_goods[i].id != -1)&&(role->medica_goods[i].iNumber != 0))
			{
				ShowRleImage_NR(lW+59+((i&0x7)<<5)+((i&0x7)<<2), lH+72+(((i>>3)<<5)+((i>>3)<<2)), 0, 0, goods_selectedRLE, pS[SBuffer], SP[SBuffer]);
				DDS[SBuffer]->GetDC(&hdc);
				cFont.UseFont(hdc,DCF_USERDEFINE, 15);
				j = 0;
				pInfo = (char *)Goods->Goods[role->medica_goods[i].id].wInfo;
				info[j] = pInfo[j];
				while((pInfo[j] != -93)||(pInfo[j+1] != -70))
				{
					j++;
					info[j] = pInfo[j];
				}
				k = j+1;
				info[k] = pInfo[k];
				k ++;
				info[k] = '\0';
				ShowText(hdc, lW+65, lH+276, RGB(0,0,0), info);
				j = 0;
				info[j] = pInfo[k];
				while(info[j] != '\0')
				{
					j++;
					info[j] = pInfo[k+j];
				}
				ShowText(hdc, lW+65, lH+300, RGB(0,0,0), info);
				cFont.RestoreFont(hdc);
				DDS[SBuffer]->ReleaseDC(hdc);
			}
		}
		break;
	case 5:
		i = id_newgame&0x0ff;
		switch(i)
		{
		case 0:
			ShowRleImage_NR(lW+75, lH+80, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+96, 0, 0, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+75, lH+170, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+186, 0, 1, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+75, lH+260, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+276, 0, 2, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			break;
		case 1:
			ShowRleImage_NR(lW+75, lH+80, 0, 0, system_sel2RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+96, 0, 0, system_sel_textRLE, pS[SBuffer], SP[SBuffer]);

			ShowRleImage_NR(lW+75, lH+170, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+186, 0, 1, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+75, lH+260, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+276, 0, 2, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			break;
		case 2:
			ShowRleImage_NR(lW+75, lH+80, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+96, 0, 0, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);

			ShowRleImage_NR(lW+75, lH+170, 0, 0, system_sel2RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+186, 0, 1, system_sel_textRLE, pS[SBuffer], SP[SBuffer]);

			ShowRleImage_NR(lW+75, lH+260, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+276, 0, 2, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			break;
		case 3:
			ShowRleImage_NR(lW+75, lH+80, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+96, 0, 0, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+75, lH+170, 0, 0, system_sel1RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+186, 0, 1, system_unsel_textRLE, pS[SBuffer], SP[SBuffer]);

			ShowRleImage_NR(lW+75, lH+260, 0, 0, system_sel2RLE, pS[SBuffer], SP[SBuffer]);
			ShowRleImage_NR(lW+105, lH+276, 0, 2, system_sel_textRLE, pS[SBuffer], SP[SBuffer]);
			break;
		}
		break;
	case 6:
	default:
		return;
	}
}

void UseEquip(int id)
{
	int i;
	if(role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1] == -1)
	{
		role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1] = role->equip_goods[id].id;
		role->equip_goods[id].iNumber --;
		Goods->UseGoods(role, Goods->Goods[role->equip_goods[id].id].dType, role->equip_goods[id].id);
		if(role->equip_goods[id].iNumber == 0)
			role->equip_goods[id].id = -1;
		return;
	}
	else if(role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1] == role->equip_goods[id].id)
	{
		return;
	}
	else
	{
		for(i = 0; i < MaxEquip_Schlep; i++)
		{
			if(role->equip_goods[i].id == role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1])
			{
				Goods->RemoveEquip(role, Goods->Goods[role->equip_goods[id].id].dType, role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1]);
				role->equip_goods[i].iNumber ++;
				role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1] = role->equip_goods[id].id;
				role->equip_goods[id].iNumber -= 1;
				Goods->UseGoods(role, Goods->Goods[role->equip_goods[id].id].dType, role->equip_goods[id].id);
				if(role->equip_goods[id].iNumber == 0)
					role->equip_goods[id].id = -1;
				return;
			}
		}
		for(i = 0; i < MaxEquip_Schlep; i++)
		{
			if(role->equip_goods[i].id == -1)
			{
				Goods->RemoveEquip(role, Goods->Goods[role->equip_goods[id].id].dType, role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1]);
				role->equip_goods[i].id = role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1];
				role->equip_goods[i].iNumber = 1;
				role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1] = role->equip_goods[id].id;
				role->equip_goods[id].iNumber --;
				Goods->UseGoods(role, Goods->Goods[role->equip_goods[id].id].dType, role->equip_goods[id].id);
				if(role->equip_goods[id].iNumber == 0)
					role->equip_goods[id].id = -1;
				return;
			}
		}
		Goods->RemoveEquip(role, Goods->Goods[role->equip_goods[id].id].dType, role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1]);
		role->equiped[Goods->Goods[role->equip_goods[id].id].dType-1] = role->equip_goods[id].id;
		role->equip_goods[id].iNumber --;
		Goods->UseGoods(role, Goods->Goods[role->equip_goods[id].id].dType, role->equip_goods[id].id);
		if(role->equip_goods[id].iNumber == 0)
			role->equip_goods[id].id = -1;
	}
}

void RemoveEquip(int id)
{
	int i;
	Goods->RemoveEquip(role, id+1, role->equiped[id]);
		for(i = 0; i < MaxEquip_Schlep; i++)
		{
			if(role->equip_goods[i].id == role->equiped[id])
			{
				role->equip_goods[i].iNumber ++;
				role->equiped[id] = -1;
				return;
			}
		}
		for(i = 0; i < MaxEquip_Schlep; i++)
		{
			if(role->equip_goods[i].id == -1)
			{
				role->equip_goods[i].id = role->equiped[id];
				role->equip_goods[i].iNumber = 1;
				role->equiped[id] = -1;
				return;
			}
		}
		role->equiped[id] = -1;
}

void PlayMagic(MagicIsUsing *magic)
{
	RECT rect1;
	rect1.left = magic->x - (int)dMap_StartX - (int)((magicRLE[magic->id]->bfWidth/magicRLE[magic->id]->bfWidthBitN)>>1) > 0? 0 : (int)((magicRLE[magic->id]->bfWidth/magicRLE[magic->id]->bfWidthBitN)>>1) + (int)dMap_StartX - magic->x;
	rect1.top = magic->y - (int)dMap_StartY - (int)magicRLE[magic->id]->bfHeight > 0? 0 : (int)magicRLE[magic->id]->bfHeight + (int)dMap_StartY - magic->y;
	rect1.right = magic->x - (int)dMap_StartX + (int)((magicRLE[magic->id]->bfWidth/magicRLE[magic->id]->bfWidthBitN)>>1) > SCREEN_WIDTH? SCREEN_WIDTH + (int)((magicRLE[magic->id]->bfWidth/magicRLE[magic->id]->bfWidthBitN)>>1) + (int)dMap_StartX - magic->x : (int)magicRLE[magic->id]->bfWidth/magicRLE[magic->id]->bfWidthBitN;
	rect1.bottom = magicRLE[magic->id]->bfHeight;

	ShowRleImage(magic->x-(int)dMap_StartX-(int)((magicRLE[magic->id]->bfWidth/magicRLE[magic->id]->bfWidthBitN)>>1)+rect1.left, magic->y-(int)dMap_StartY-(int)magicRLE[magic->id]->bfHeight+rect1.top, magic->n, 0, rect1, magicRLE[magic->id], pS[SBuffer], SP[SBuffer]);
}

void AddMagicToLink( )
{
	static DWORD	AddMagicTime = 0;
	int	TimeDiscrepancy = abs(time - AddMagicTime);
	MagicIsUsing * magic_Link;  //中介指针
	int i;
	if(TimeDiscrepancy > GameSpeed-1)
	{
		if((role->Waittime > 0)&&(role->MainStatus != AWAY)&&(role->MainStatus != DIE))
		{
			role->Waittime -= TimeDiscrepancy/GameSpeed;
			if(role->Waittime <= 0)
			{
				magic_Link = new MagicIsUsing;
				magic_Link->id = role->MagicUsing.id;
				magic_Link->life = role->MagicUsing.life;
				magic_Link->n = role->MagicUsing.n;
				magic_Link->x = role->MagicUsing.x;
				magic_Link->y = role->MagicUsing.y;
				magic_Link->owner = role->MagicUsing.owner;
				magic_Link->IsMagicShowing = role->MagicUsing.IsMagicShowing;
				magic_Link->Back = NULL;
				if(magic_using == NULL)
				{
					magic_using = magic_Link;
					magic_using->Next = NULL;
				}
				else
				{
					magic_Link->Next = magic_using;
					magic_using->Back = magic_Link;
					magic_using = magic_Link;
				}
				magic_Link = NULL;
				role->Waittime = -1;
			}
		}
		for(i = 0; i < (int)(Zoetic->ZoeticHeader.nMagicN); i++)
		{
			if((Zoetic->Waittime[i] > 0)&&(Zoetic->MainStatus[i] != AWAY)&&(Zoetic->MainStatus[i] != DIE))
			{
				Zoetic->Waittime[i] -= TimeDiscrepancy/GameSpeed;
				if(Zoetic->Waittime[i] <= 0)
				{
					magic_Link				= new MagicIsUsing;
					magic_Link->id			= Zoetic->MagicUsing[i].id;
					magic_Link->life		= Zoetic->MagicUsing[i].life;
					magic_Link->n			= Zoetic->MagicUsing[i].n;
					magic_Link->x			= Zoetic->MagicUsing[i].x;
					magic_Link->y			= Zoetic->MagicUsing[i].y;
					magic_Link->owner		= Zoetic->MagicUsing[i].owner;
					magic_Link->IsMagicShowing = Zoetic->MagicUsing[i].IsMagicShowing;
					magic_Link->Back		= NULL;
					if(magic_using == NULL)
					{
						magic_using			= magic_Link;
						magic_using->Next	= NULL;
					}
					else
					{
						magic_Link->Next	= magic_using;
						magic_using->Back	= magic_Link;
						magic_using			= magic_Link;
					}
					magic_Link = NULL;
					Zoetic->Waittime[i] = -1;
				}
			}
		}
		AddMagicTime = time;
	}
}

void ChangeMagicStatus( )
{
	static DWORD MagicTime = 0;
	int  TimeDiscrepancy = abs(time - MagicTime);
	MagicIsUsing * magic_Link = magic_using;
	MagicIsUsing * magic_Link1;
	if(TimeDiscrepancy > GameSpeed-1)
	{
		while(magic_Link)
		{
			magic_Link->n += TimeDiscrepancy/GameSpeed;
			if(magic_Link->n >= magic_Link->life)
			{
				if(magic_Link->IsMagicShowing)		//若魔法正在显示,则不删除魔法
				{
					magic_Link->n	= magic_Link->life-1;
					magic_Link		= magic_Link->Next;
					continue;
				}
				if(magic_Link->Next == NULL)
				{
					if(magic_Link->Back == NULL)
					{
						P_SAFE_DELETE(magic_Link);
						magic_using = NULL;
						break;
					}
					else
					{
						magic_Link->Back->Next = NULL;
						P_SAFE_DELETE(magic_Link);
						break;
					}
				}
				else
				{
					if(magic_Link->Back == NULL)
					{
						magic_using = magic_using->Next;
						magic_Link = magic_Link->Next;
						P_SAFE_DELETE(magic_Link->Back);
						magic_Link->Back = NULL;
					}
					else
					{
						magic_Link1 = magic_Link;
						magic_Link->Back->Next = magic_Link->Next;
						magic_Link->Next->Back = magic_Link->Back;
						magic_Link = magic_Link->Next;
						P_SAFE_DELETE(magic_Link1);
					}
				}
			}
			else
			{	
				magic_Link = magic_Link->Next;
			}
		}
		MagicTime = time;
	}
}

void ChangeAttackTextStatus( )
{
	static DWORD AttackTime = 0;
	DWORD  TimeDiscrepancy = abs(time - AttackTime);
	AttackText * attacktext_Link = Attack_Text;
	AttackText * attacktext_Link1;
	while(attacktext_Link)
	{
		attacktext_Link->life -= TimeDiscrepancy;
		if(attacktext_Link->life <= 0)
		{
			if(attacktext_Link->IsShowing)		//若魔法正在显示,则不删除魔法
			{
				attacktext_Link->life	= attacktext_Link->life-1;
				attacktext_Link			= attacktext_Link->Next;
				continue;
			}
			if(attacktext_Link->Next == NULL)
			{
				if(attacktext_Link->Back == NULL)
				{
					P_SAFE_DELETE(attacktext_Link);
					Attack_Text = NULL;
					break;
				}
				else
				{
					attacktext_Link->Back->Next = NULL;
					P_SAFE_DELETE(attacktext_Link);
					break;
				}
			}
			else
			{
				if(attacktext_Link->Back == NULL)
				{
					Attack_Text = Attack_Text->Next;
					attacktext_Link = attacktext_Link->Next;
					P_SAFE_DELETE(attacktext_Link->Back);
					attacktext_Link->Back = NULL;
				}
				else
				{
					attacktext_Link1 = attacktext_Link;
					attacktext_Link->Back->Next = attacktext_Link->Next;
					attacktext_Link->Next->Back = attacktext_Link->Back;
					attacktext_Link = attacktext_Link->Next;
					P_SAFE_DELETE(attacktext_Link1);
				}
			}
		}
		else
		{	
			attacktext_Link = attacktext_Link->Next;
		}
	}
	AttackTime = time;
}

DWORD RoleTime = 0;
DWORD RoleTime1 = 0;
void MovRole( )
{
	int  TimeDiscrepancy = abs(time - RoleTime);
	int i, j;
	//-----------------------------移动主角------------
	if((role->WalkNumber != -1)&&(role->MainStatus != AWAY)&&(role->MainStatus != DIE))
	{
		if(role->FollowID != -1)
		{
			if((abs(role->y - Zoetic->ZoeticLink[role->FollowID].dCurrent_y) < 50)&&(abs(role->x-Zoetic->ZoeticLink[role->FollowID].dCurrent_x) < 50))
			{
				if(Zoetic->ZoeticLink[role->FollowID].dEvent != -1)
				{
					for(i = 0; i < 10; i++)
					{
						if(Script_Child[i].iScriptID == Zoetic->ZoeticLink[role->FollowID].dEvent)
						{
							Script_Child[i].Run();
							break;
						}
					}
					if(i == 10)
					{
						MsgBox("找不到脚本文件:第 %d 号",Zoetic->ZoeticLink[role->FollowID].dEvent);
					}
				}
				role->FollowID = -1;
			}
			else
			{
				role->moveto(Zoetic->ZoeticLink[role->FollowID].dCurrent_x, Zoetic->ZoeticLink[role->FollowID].dCurrent_y);
			}	
		}
		if(TimeDiscrepancy > GameSpeed-1)
		{
			role->MoveTheRole(TimeDiscrepancy/GameSpeed);
			RoleTime = time;
		}
		if((time%((6-role->speed/3)*GameSpeed))==0) //改脚的状态
		{
			role->FootStatus=(role->FootStatus+1)%5;
			if(role->FootStatus == 0)
				role->FootStatus = 1;
		}
		if(time%(GameSpeed*5) == 0)
			PurposeTimes = (PurposeTimes+1)%3;
	}
	else
	{
		if((role->MainStatus == AWAY)||(role->MainStatus == DIE))
		{
			NewGameSelect = 9;
			NewGameOut = true;
			return;
		}
		else
		{
			role->FootStatus=-1;
			RoleTime = time;
		}
	}
	MagicIsUsing * magic_Link;  //中介指针
	magic_Link = magic_using;
	if(abs(time-RoleTime1) > 40)
	{
		while(magic_Link)
		{
			if((abs(magic_Link->y - role->y) <  (int)(Magic->Magic[magic_Link->id].wArea<<5))&&(abs(magic_Link->x - role->x) < (int)(Magic->Magic[magic_Link->id].wArea<<5)))
			{
				 Magic->AttackMagic(role, Magic->Magic[magic_Link->id].dType, magic_Link);
				 Add_AttackText(role->x, role->y, magic_Link->id);
			}
			magic_Link = magic_Link->Next;
		}
		RoleTime1 = time;
	}
	if((Map->pSurfaceData[(role->y>>5)*Map->pHeader.nWidth+(role->x>>5)].nEvent != -1)&&(Map->pSurfaceData[(role->y>>5)*Map->pHeader.nWidth+(role->x>>5)].nEvent != 0))
	{
		j = Map->pSurfaceData[(role->y>>5)*Map->pHeader.nWidth+(role->x>>5)].nEvent;
		for(i = 0; i < 10; i++)
		{
			if(Script_Child[i].iScriptID == j)
			{
				Script_Child[i].Run();
				break;
			}
		}
		if(i == 10)
		{
			MsgBox("找不到脚本文件:第 %d 号",j);
		}
	}
}

void MovZoetic( )
{
	int i;
	for(i = 0; i < (int)(Zoetic->ZoeticHeader.nMagicN); i++)
	{
		if((Zoetic->MainStatus[i] != AWAY)&&(Zoetic->MainStatus[i] != DIE))
		{
			Zoetic->Action(i);
		}
	}
}

//----------------------------改变地图中的动态元素----------------------
void ChangeTheDynamicPic( )
{
	static DWORD	DynamicTime = 0;
	int i;
	for(i = 0; i < DYNAMICPICNUMBER; i++)
	{
		iTime1[i] += abs(time - DynamicTime);
		if(iTime1[i] >= iTime[i]*GameSpeed)
		{
			iChangePic[i] = (iChangePic[i]+1)%(pSourCell[21+i].pBmpHeader->bfWidth>>5);
			iTime1[i] = 0;
		}
	}
	DynamicTime = time;
}

void IsMouseOnSomeone( )
{
	int i;
	char str[30];
	int x = curpos.x+dMap_StartX;
	int y = curpos.y+dMap_StartY;
	HDC	 hdc;
	CFont cFont;
	for(i = 0; i < (int)Zoetic->ZoeticHeader.nMagicN; i++)
	{
		if(((int)(Zoetic->ZoeticLink[i].dCurrent_y>>5) == y>>5)&&((int)(Zoetic->ZoeticLink[i].dCurrent_x >>5) == x>>5))
		{
			switch(Zoetic->ZoeticLink[i].dType)
			{
			case 0:				//普通NPC
				if(iMouseType != 11)
				{
					cursor = 0;
					PA_SAFE_DELETE(mouseRLE);
					mouseRLE = LoadRleImage("Pic\\cursor\\NPC.ret");
					cursorT = 11;
					iMouseType = 11;
					DDS[SBuffer]->GetDC(&hdc);
					cFont.UseFont(hdc,DCF_NOMAL);
					sprintf(str, "生命: %d", (int)Zoetic->ZoeticLink[i].health);
					ShowText(hdc, 350, 40, RGB(255,0,0), str);
					cFont.RestoreFont(hdc);
					DDS[SBuffer]->ReleaseDC(hdc);
				}
				iMouseInZoetic = i;
				break;
			case 7:				//敌人
				if(iMouseType != 8)
				{
					cursor = 0;
					PA_SAFE_DELETE(mouseRLE);
					mouseRLE = LoadRleImage("Pic\\cursor\\enemy.ret");
					cursorT = 8;
					iMouseType = 8;
					DDS[SBuffer]->GetDC(&hdc);
					cFont.UseFont(hdc,DCF_NOMAL);
					sprintf(str, "生命: %d", (int)Zoetic->ZoeticLink[i].health);
					ShowText(hdc, 350, 40, RGB(255,0,0), str);
					cFont.RestoreFont(hdc);
					DDS[SBuffer]->ReleaseDC(hdc);
				}
				iMouseInZoetic = i;
				break;
			default:
				break;
			}
			break;
		}
	}
	if(i == (int)Zoetic->ZoeticHeader.nMagicN)
	{
		JudgeMousePlace( );
		if(id_newgame != 0)
		{
			if(iMouseType != 1)
			{
				cursor = 0;
				PA_SAFE_DELETE(mouseRLE);
				mouseRLE = LoadRleImage("Pic\\cursor\\cursor01.ret");
				cursorT = 4;
				iMouseType = 1;
			}
		}
		else if(iMouseType != 3)
		{
			cursor = 0;
			PA_SAFE_DELETE(mouseRLE);
			mouseRLE = LoadRleImage("Pic\\cursor\\cursor03.ret");
			cursorT = 4;
			iMouseType = 3;
		}
		iMouseInZoetic = -1;
	}
}

bool Fire(int iOwner, int x, int y, int iMagicId)
{
	Zoetic->FaceTo(iOwner, x, y);
	if((abs(x - Zoetic->ZoeticLink[iOwner].dCurrent_x) < (long)(Magic->Magic[iMagicId].wDistance<<5))
	 &&(abs(y - Zoetic->ZoeticLink[iOwner].dCurrent_y) < (long)(Magic->Magic[iMagicId].wDistance<<5)))
	{
		if(Zoetic->Waittime[iOwner] != -1)
			return false;
		if(!Magic->UseMagic(iOwner, Magic->Magic[iMagicId].dType, iMagicId))
			return false;
		Zoetic->Waittime[iOwner] = magicRLE_user->bfWidthBitN;
		Zoetic->MagicUsing[iOwner].id = iMagicId;
		Zoetic->MagicUsing[iOwner].x  = x;
		Zoetic->MagicUsing[iOwner].y  = y;
		Zoetic->MagicUsing[iOwner].n  = 0;
		Zoetic->MagicUsing[iOwner].owner = Zoetic->ZoeticLink[iOwner].dType;
		Zoetic->MagicUsing[iOwner].IsMagicShowing = false;
		Zoetic->MagicUsing[iOwner].life = magicRLE[iMagicId]->bfWidthBitN;
		Zoetic->MagicUsing[iOwner].Back = NULL;
		return true;
	}
	return false;
}

void Add_AttackText(int x, int y, int magicid)
{
	AttackText   * Text_Link;
	Text_Link = new AttackText;
	Text_Link->x = x;
	Text_Link->y = y;
	Text_Link->id = magicid;
	Text_Link->life = 100;
	Text_Link->Back = NULL;
	if(Attack_Text == NULL)
	{
		Attack_Text = Text_Link;
		Text_Link->Next = NULL;
		Text_Link = NULL;
		return;
	}
	else
	{
		Text_Link->Next = Attack_Text;
		Attack_Text->Back = Text_Link;
		Attack_Text = Text_Link;
		Text_Link = NULL;
		return;
	}
	return;
}

void Show_AttackText(AttackText * TextLink)
{
	char str[30];
	int  x;
	int  y;
	HDC	 hdc;
	CFont cFont;
	DDS[SBuffer]->GetDC(&hdc);
	cFont.UseFont(hdc,DCF_NOMAL);
	TEXTMETRIC tm;
	GetTextMetrics(hdc,&tm);
	x = TextLink->x - tm.tmAveCharWidth*2 - dMap_StartX;
	y = TextLink->y - dMap_StartY;
	if(Magic->Magic[TextLink->id].wHealth != 0)
	{
		sprintf(str, "生命: %d", (int)Magic->Magic[TextLink->id].wHealth);
		ShowText(hdc, x, y, RGB(255,0,0), str);
		y -= tm.tmHeight+tm.tmExternalLeading;
	}
	if(Magic->Magic[TextLink->id].wEnergy != 0)
	{
		sprintf(str, "内力: %d", (int)Magic->Magic[TextLink->id].wEnergy);
		ShowText(hdc, x, y, RGB(0,255,0), str);
		y -= tm.tmHeight+tm.tmExternalLeading;
	}
	if(Magic->Magic[TextLink->id].wVigor != 0)
	{
		sprintf(str, "精力: %d", (int)Magic->Magic[TextLink->id].wEnergy);
		ShowText(hdc, x, y, RGB(0,0,255), str);
	}

	cFont.RestoreFont(hdc);
	DDS[SBuffer]->ReleaseDC(hdc);

}